<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/11
 * Time: 17:02
 */
namespace app\home\controller;

use app\home\controller\Base;

class Order extends Base {

    protected $model;
    /**
     * 初始化
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Order');
    }
    
    /**
     * 我的购卡订单列表
     */
    public function index()
    {
        $order = $this->model->getOrderListM();
        $this->assign('order',$order);
        return view();
    }

    /**
     * 订单详情
     */
    public function details()
    {
        $details = $this->model->getOrderListM();
        $this->assign('details',$details['data'][0]);
        return view();
    }

    /**
     * 取消订单
     */
    public function cancelOrder()
    {
        $status = 3;
        $cancel = $this->model->changeOrderM($status);
        if($cancel['code']){
            return ['code'=>1,'msg'=>'取消订单失败！'];
        }
        return ['code'=>0,'msg'=>'取消订单成功！'];
    }

    /**
     * 提交订单后显示支付页面
     */
    public function payment()
    {
        $where['status'] = '2';
        $details = $this->model->getOrderListM($where);
        if(!$details){
            $this->error();
        }
        $this->assign('details',$details['data'][0]);
        // 获取账户余额
        $balance = model('Personal')->getMyAccountBalanceM();
        $this->assign('balance',$balance);
        return view();
    }
    
    /**
     * 支付订单
     */
    public function payOrder()
    {
        $status = 1;
        $pay = $this->model->changeOrderM($status);
        if($pay['code']){
            return ['code'=>1,'msg'=>'支付订单失败！'];
        }
        return ['code'=>0,'msg'=>'支付订单成功！'];
    }
    
}